//! @file   lc_interval.h
//! @brief  
//! @author Sayan Chaliha
//! @date   September, 2011
//!
//! 
#ifndef _LC_INTERVAL_H
#define _LC_INTERVAL_H

#include "libcyan_internal.h"
#include "lc_types.h"
#include "lc_object.h"

namespace cyan {
    class CYAN_API Interval : public Object {
    public:
        static const UInt MILLISECONDS_PER_SECOND = 1000;
        static const UInt MICROSECONDS_PER_SECOND = 1000 * 1000;
        
        enum ReservedInterval {
            NO_WAIT,
            NOW,
            NO_TIMEOUT
        };
        
        Interval();
        Interval(const Interval&);
        Interval(ReservedInterval);
        Interval(const IntervalTime&);
        
        void setToNow();
        Time toSeconds() const;
        Time toMilliseconds() const;
        Time toMicroseconds() const;
        static Time toSeconds(IntervalTime);
        static Time toMilliseconds(IntervalTime);
        static Time toMicroseconds(IntervalTime);
        static Interval fromSeconds(Time);
        static Interval fromMilliseconds(Time);
        static Interval fromMicroseconds(Time);
        static IntervalTime now();
        
        Interval operator -(const Interval&) const;
        Interval operator +(const Interval&) const;
        Interval operator /(const Interval&) const;
        Interval operator *(const Interval&) const;
        Interval& operator =(const Interval&);
        Interval& operator =(const IntervalTime&);
        Interval& operator -=(const Interval&);
        Interval& operator +=(const Interval&);
        Interval& operator /=(const Interval&);
        Interval& operator *=(const Interval&);
        Bool operator <(const Interval&) const;
        Bool operator >(const Interval&) const;
        Bool operator <=(const Interval&) const;
        Bool operator >=(const Interval&) const;
        Bool operator ==(const Interval&) const;
        Bool operator !=(const Interval&) const;
        operator IntervalTime() const;
        
    private:
        IntervalTime interval_;
        
        friend IntervalTime operator -(const IntervalTime&, const Interval&);
        friend IntervalTime operator +(const IntervalTime&, const Interval&);
        friend IntervalTime operator /(const IntervalTime&, const Interval&);
        friend IntervalTime operator *(const IntervalTime&, const Interval&);
        
        friend IntervalTime& operator -=(IntervalTime&, const Interval&);
        friend IntervalTime& operator +=(IntervalTime&, const Interval&);
        friend IntervalTime& operator /=(IntervalTime&, const Interval&);
        friend IntervalTime& operator *=(IntervalTime&, const Interval&);
        
        friend Bool operator <(const IntervalTime&, const Interval&);
        friend Bool operator >(const IntervalTime&, const Interval&);
        friend Bool operator <=(const IntervalTime&, const Interval&);
        friend Bool operator >=(const IntervalTime&, const Interval&);
        friend Bool operator ==(const IntervalTime&, const Interval&);
        friend Bool operator !=(const IntervalTime&, const Interval&);
    };
    
    IntervalTime CYAN_API operator -(const IntervalTime&, const Interval&);
    IntervalTime CYAN_API operator +(const IntervalTime&, const Interval&);
    IntervalTime CYAN_API operator /(const IntervalTime&, const Interval&);
    IntervalTime CYAN_API operator *(const IntervalTime&, const Interval&);
    
    IntervalTime& operator -=(IntervalTime&, const Interval&);
    IntervalTime& operator +=(IntervalTime&, const Interval&);
    IntervalTime& operator /=(IntervalTime&, const Interval&);
    IntervalTime& operator *=(IntervalTime&, const Interval&);
    
    Bool CYAN_API operator <(const IntervalTime&, const Interval&);
    Bool CYAN_API operator >(const IntervalTime&, const Interval&);
    Bool CYAN_API operator <=(const IntervalTime&, const Interval&);
    Bool CYAN_API operator >=(const IntervalTime&, const Interval&);
    Bool CYAN_API operator ==(const IntervalTime&, const Interval&);
    Bool CYAN_API operator !=(const IntervalTime&, const Interval&);
}

#endif /* _LC_INTERVAL_H */
